#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python_learning 
@File ：桥接模式.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/3/1 23:54 
"""

"""
桥接模式（Bridge Pattern）
模式解释：
桥接模式将抽象部分与其实现部分分离，使它们可以独立地变化。
"""

from abc import ABC, abstractmethod


class Implementor(ABC):
	@abstractmethod
	def operation_imp(self):
		pass


class ConcreteImplementorA(Implementor):
	def operation_imp(self):
		return "ConcreteImplementorA operation"


class ConcreteImplementorB(Implementor):
	def operation_imp(self):
		return "ConcreteImplementorB operation"


class Abstraction:
	def __init__(self, imp):
		self._imp = imp

	def operation(self):
		return f"Abstraction: Base operation with:\n{self._imp.operation_imp()}"


class RefinedAbstraction(Abstraction):
	def operation(self):
		return (
			f"RefinedAbstraction: Extended operation with:\n{self._imp.operation_imp()}"
		)


implementor_a = ConcreteImplementorA()
implementor_b = ConcreteImplementorB()

abstraction_a = Abstraction(implementor_a)
abstraction_b = RefinedAbstraction(implementor_b)

print(abstraction_a.operation())
print(abstraction_b.operation())
